import { applyMiddleware, createStore } from 'redux';

import thunk from 'redux-thunk';

import reducers from './reducers';

const create = window.devToolsExtension
  ? window.devToolsExtension()(createStore)
  : createStore;
const store = create(reducers, applyMiddleware(thunk));

if (module.hot) {
  module.hot.accept('./reducers/index.js', () => {
    const nextRootReducer = require('./reducers/index.js').default;
    store.replaceReducer(nextRootReducer);
  });
}

export default store;
